import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		vid: '',
		shopId: '',
		uid: '',
		bid: '',
		shareData: '',
	},
	mutations: {
		getVid(state, payload) {
			state.vid = payload;
		},
		updateDate(state, payload) {
			if (payload.shop_id) state.shopId = payload.shop_id;
			if (payload.uid) state.uid = payload.uid;
			if (payload.bid) state.bid = payload.bid;
			if (payload.shareData) state.shareData = payload.shareData;
		}
	},

	plugins: [
		createPersistedState({
			key: 'adminH5',
			paths: [
				'vid',
				'shopId',
				'uid',
				'bid',
				'shareData'
			],
			storage: {
				getItem: (key) => uni.getStorageSync(key), // 获取
				setItem: (key, value) => uni.setStorageSync(key, value), // 存储
				removeItem: (key) => uni.removeStorageSync(key) // 删除
			}
		})

	]
})

export default store